/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package livro.frames;

import livro.control.BookFrameDadosSave;
import bibliinfo.FrameMain;
import java.util.ArrayList;
import java.util.List;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import livro.model.Livro;
import livro.model.LivroDao;
import livro.model.LivroExe;
import usuario.model.UsuarioDao;
import utilitarios.Validar;

/**
 *
 * @author Ar0n
 */
public class BookFrameMain extends javax.swing.JInternalFrame {

    /**
     * Creates new form UserFrameMain
     */
    public BookFrameMain() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jPanel1 = new javax.swing.JPanel();
        jBPesquisa = new javax.swing.JButton();
        jTPesquisar = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jTBTitulo = new javax.swing.JToggleButton();
        jTBISBN = new javax.swing.JToggleButton();
        jTBSim = new javax.swing.JToggleButton();
        jTBNao = new javax.swing.JToggleButton();
        jPanel2 = new javax.swing.JPanel();
        jBCadastrar = new javax.swing.JButton();
        jBAbrir = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable = new javax.swing.JTable();

        jMenu1.setText("jMenu1");

        jMenuItem1.setText("jMenuItem1");
        jMenu1.add(jMenuItem1);

        jMenuItem2.setText("jMenuItem2");

        jBPesquisa.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jBPesquisa.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/img_user/1365775621_green-37.png"))); // NOI18N
        jBPesquisa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBPesquisaActionPerformed(evt);
            }
        });

        jTPesquisar.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jTPesquisar.setPreferredSize(new java.awt.Dimension(0, 10));
        jTPesquisar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTPesquisarKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTPesquisarKeyReleased(evt);
            }
        });

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel5.setText("Configurações de Pesquisa");
        jLabel5.setPreferredSize(new java.awt.Dimension(20, 15));

        jLabel6.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel6.setText("Pesquisar Excluidos:");
        jLabel6.setPreferredSize(new java.awt.Dimension(20, 15));

        jLabel7.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel7.setText("Pesquisar por:");
        jLabel7.setPreferredSize(new java.awt.Dimension(20, 15));

        jTBTitulo.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jTBTitulo.setSelected(true);
        jTBTitulo.setText("Título");
        jTBTitulo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTBTituloActionPerformed(evt);
            }
        });

        jTBISBN.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jTBISBN.setText("ISBN");
        jTBISBN.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTBISBNActionPerformed(evt);
            }
        });

        jTBSim.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jTBSim.setText("Sim");
        jTBSim.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTBSimActionPerformed(evt);
            }
        });

        jTBNao.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jTBNao.setSelected(true);
        jTBNao.setText("Não");
        jTBNao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTBNaoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(11, 11, 11)
                        .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 583, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addComponent(jTBTitulo, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTBISBN, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addComponent(jTBNao, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTBSim, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTPesquisar, javax.swing.GroupLayout.PREFERRED_SIZE, 350, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jBPesquisa)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jTBTitulo, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jTBISBN, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jTPesquisar, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBPesquisa, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(4, 4, 4)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTBSim, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTBNao, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jBCadastrar.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jBCadastrar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/img_livro/136526tyty7550_books.png"))); // NOI18N
        jBCadastrar.setText("Cadastrar Livro");
        jBCadastrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBCadastrarActionPerformed(evt);
            }
        });

        jBAbrir.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jBAbrir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/img_user/1365307745_Open.png"))); // NOI18N
        jBAbrir.setText("Abrir");
        jBAbrir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBAbrirActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addComponent(jBCadastrar, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jBAbrir, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(20, 20, 20))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(35, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBCadastrar, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBAbrir, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(35, 35, 35))
        );

        jScrollPane1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        jTable.setModel(defaultTable);
        jTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTableMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTable);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane1)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 358, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jBCadastrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBCadastrarActionPerformed
        
        FrameMain.bookFrameMain.setVisible(false);
        FrameMain.bookFrameMain.setEstado(false);
                
        FrameMain.bookFrameCad.setVisible(true);
        FrameMain.bookFrameCad.setEstado(true);
        //formatando frame
        FrameMain.mapa.put("frame22", FrameMain.bookFrameCad);
        FrameMain.formata(22);
        
        BookFrameDadosSave save = new BookFrameDadosSave();
        save.limparCampos();
    }//GEN-LAST:event_jBCadastrarActionPerformed

    private void jBPesquisaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBPesquisaActionPerformed
       pesquisar();
    }//GEN-LAST:event_jBPesquisaActionPerformed

    private void jTBTituloActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTBTituloActionPerformed
        alternarNome(true);
    }//GEN-LAST:event_jTBTituloActionPerformed

    private void jTBISBNActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTBISBNActionPerformed
        alternarNome(false);
    }//GEN-LAST:event_jTBISBNActionPerformed

    private void jTBNaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTBNaoActionPerformed
        alternarExcluido(true);
    }//GEN-LAST:event_jTBNaoActionPerformed

    private void jTBSimActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTBSimActionPerformed
        alternarExcluido(false);
    }//GEN-LAST:event_jTBSimActionPerformed

    private void jTPesquisarKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTPesquisarKeyPressed
        if(jTBTitulo.isSelected() == true){
            Validar.validaTexto(jTPesquisar, 50);
        }else{
            Validar.validaNum(jTPesquisar, 13);
        }
    }//GEN-LAST:event_jTPesquisarKeyPressed

    private void jTPesquisarKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTPesquisarKeyReleased
        if(jTBTitulo.isSelected() == true){
            Validar.validaTexto(jTPesquisar, 50);
            pesquisar();
        }else{
            Validar.validaNum(jTPesquisar, 13);
            pesquisar();
        }
        
    }//GEN-LAST:event_jTPesquisarKeyReleased

    private void jBAbrirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBAbrirActionPerformed
        try{
            if(ISBNSelecionado.equalsIgnoreCase("") == true){
                JOptionPane.showMessageDialog(FrameMain.bookFrameMain, "Selecione um Livro na tabela", "", 1);
            }else{            
                updateBook();
            }
        }catch(Exception e){
            System.out.println("null");
        }        
    }//GEN-LAST:event_jBAbrirActionPerformed

    private void jTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTableMouseClicked
        pegarLivro();
    }//GEN-LAST:event_jTableMouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBAbrir;
    private javax.swing.JButton jBCadastrar;
    private javax.swing.JButton jBPesquisa;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JToggleButton jTBISBN;
    private javax.swing.JToggleButton jTBNao;
    private javax.swing.JToggleButton jTBSim;
    private javax.swing.JToggleButton jTBTitulo;
    private javax.swing.JTextField jTPesquisar;
    private javax.swing.JTable jTable;
    // End of variables declaration//GEN-END:variables
    //atributos
    private static boolean estado = true;//true = visivel false = não visivel
    public DefaultTableModel defaultTable = new DefaultTableModel(null, new String [] {"Título", "ISBN"});
    public Object [] linhas;
    public String ISBNSelecionado = "";
    public List<LivroExe> listaLivroRealQuero = new ArrayList<>();
    //métodos
    
    /**
     * Método criado para identicar o estado do frame
     */   
    public boolean getEstado(){
        return estado;
    }
    public void setEstado(boolean estado){
        this.estado = estado;
    }
    
    public void alternarNome(boolean b){
        if(b == true){
            jTBTitulo.setSelected(true);
            jTBISBN.setSelected(false);
        }else{
            jTBTitulo.setSelected(false);
            jTBISBN.setSelected(true);
        }
        
    }
    
    public void alternarExcluido(boolean b){
        if(b == true){
            jTBNao.setSelected(true);
            jTBSim.setSelected(false);
        }else{
            jTBNao.setSelected(false);
            jTBSim.setSelected(true);
        }
    }
    
    //limapando linhas das tabelas
    public void limparTabela(){
        while(defaultTable.getRowCount() > 0){
            defaultTable.removeRow(0);
        }
    }
    
    public void pesquisar(){
        LivroDao dao = new LivroDao();
        limparTabela();
        List<Livro> lista = dao.readA();
        if(jTPesquisar.getText().equalsIgnoreCase("") == true){            
            if(jTBNao.isSelected() == true){                
                for(Livro livro : lista){                    
                    if(livro.getAtivo() == true){
                        linhas = new Object[]{livro.getTitulo(), livro.getISBN()};
                        defaultTable.addRow(linhas);
                    }
                }
            }else{
                for(Livro livro : lista){
                    if(livro.getAtivo() == false){
                        linhas = new Object[]{livro.getTitulo(), livro.getISBN()};
                        defaultTable.addRow(linhas);
                    }
                }
            }            
        }else{
            if(jTBTitulo.isSelected() == true){
                String pesquisa = jTPesquisar.getText();
                pesquisa = "%"+pesquisa+"%";                
                lista = dao.readPesquisa(pesquisa, 1);
                if(jTBNao.isSelected() == true){
                    for(Livro livro : lista){
                        if(livro.getAtivo() == true){
                            linhas = new Object[]{livro.getTitulo(), livro.getISBN()};
                            defaultTable.addRow(linhas);
                        }                        
                    }
                }else{
                    for(Livro livro : lista){
                        if(livro.getAtivo() == false){
                            linhas = new Object[]{livro.getTitulo(), livro.getISBN()};
                            defaultTable.addRow(linhas);
                        }
                    }
                }
            }else{
                String pesquisa = jTPesquisar.getText();
                pesquisa = "%"+pesquisa+"%";
                lista = dao.readPesquisa(pesquisa, 2);
                if(jTBNao.isSelected() == true){
                    for(Livro livro : lista){
                        if(livro.getAtivo() == true){
                            linhas = new Object[]{livro.getTitulo(), livro.getISBN()};
                            defaultTable.addRow(linhas);
                        }                        
                    }
                }else{
                    for(Livro livro : lista){
                        if(livro.getAtivo() == false){
                            linhas = new Object[]{livro.getTitulo(), livro.getISBN()};
                            defaultTable.addRow(linhas);
                        }
                    }
                }
            }
        }
    }
    
    public void pegarLivro(){
        int i = jTable.getSelectedRow();
        ISBNSelecionado = String.valueOf(jTable.getValueAt(i, 1));
    }
    
    public void updateBook(){
        
        FrameMain.bookFrameAltera.desabilitarCampos();
        
        LivroDao dao = new LivroDao();
        List<Livro> listaLivro = new ArrayList<>();
        listaLivro = dao.readA();
        List<LivroExe> listaLivroReal = new ArrayList<>();
        listaLivroReal = dao.readB(); 
        if(listaLivroRealQuero.isEmpty() == false){
            for(int i =0; i <= listaLivroRealQuero.size(); i++){
                listaLivroRealQuero.remove(i);
            }            
        }    
        
        //limpando lista de livros
        while(FrameMain.bookFrameAltera.defaultTable.getRowCount() > 0){
            FrameMain.bookFrameAltera.defaultTable.removeRow(0);
        }
        for(Livro livro : listaLivro){            
            
            if(ISBNSelecionado.equalsIgnoreCase(livro.getISBN())){
                FrameMain.bookFrameMain.setVisible(false);
                FrameMain.bookFrameMain.setEstado(false);
                
                FrameMain.bookFrameAltera.setVisible(true);
                FrameMain.bookFrameAltera.setEstado(true);
                FrameMain.formata(23);
                
                FrameMain.bookFrameAltera.jTISBN.setText(livro.getISBN());
                FrameMain.bookFrameAltera.jTTitulo.setText(livro.getTitulo());
                FrameMain.bookFrameAltera.jTAutor.setText(livro.getAutor());
                FrameMain.bookFrameAltera.jTEditora.setText(livro.getEditora());
                if(livro.getAtivo() == true){                    
                    FrameMain.bookFrameAltera.setExcluir(true);
                    FrameMain.bookFrameAltera.DelouRes();
                }else{                    
                    FrameMain.bookFrameAltera.setExcluir(false);
                    FrameMain.bookFrameAltera.DelouRes();
                }              
                
                for(LivroExe exe : listaLivroReal){
                    if(ISBNSelecionado.equalsIgnoreCase(exe.getISBN())){                                           
                       listaLivroRealQuero.add(exe);
                       
                       //setando valores no jtable
                       Object [] li = new Object[]{exe.getNumSequencia() + 1};
                       FrameMain.bookFrameAltera.defaultTable.addRow(li);
                    }                    
                }
                
                if(listaLivroRealQuero.isEmpty() == false){
                
                    if(listaLivroRealQuero.get(0).getPodeEmprestar() == true){                        
                        FrameMain.bookFrameAltera.alterarPodeEmp(true);  
                    }else{                        
                        FrameMain.bookFrameAltera.alterarPodeEmp(false);  
                    }
                }                              
                FrameMain.bookFrameAltera.jTQuant.setText(String.valueOf(listaLivroRealQuero.size()));                               
            }
        }
    }
}
